using System.Collections;
using Holoville.HOTween;
using UnityEngine;

public class WeaponEffect : MonoBehaviour
{
	public ParticleSystem particleEffect;

	[HideInInspector]
	public bool disableControls;

	[HideInInspector]
	public WeaponEffectSettings settings;

	[HideInInspector]
	public WeaponEffectWatcher effectWatcher;

	[HideInInspector]
	public Humanoid humanoid;

	[HideInInspector]
	public PlayerBehavior playerBehavior;

	public virtual void Start()
	{
		if ((bool)humanoid.GetComponent<PlayerBehavior>())
		{
			playerBehavior = humanoid.GetComponent<PlayerBehavior>();
		}
		Invoke("End", settings.effectDuration);
	}

	public virtual void End()
	{
		settings.effectType = EffectType.Non;
		if ((bool)particleEffect)
		{
			particleEffect.Stop();
		}
		CancelInvoke();
		Invoke("DestroySelf", 1f);
	}

	public void DestroySelf()
	{
		settings.effectType = EffectType.Non;
		Object.Destroy(base.gameObject);
	}

	public virtual void OnDestroy()
	{
		effectWatcher.currentEffects.Remove(this);
	}

	public void DisableControls(GameObject disablePanel)
	{
		disableControls = true;
		humanoid.canMove = false;
		humanoid.canShoot = false;
		if ((bool)playerBehavior && playerBehavior.isMine)
		{
			playerBehavior.tController.jetpack.isFlying = false;
			playerBehavior.tController.jetpack.DeactivateParticles();
			disablePanel.SetActive(true);
			UIPanel component = disablePanel.GetComponent<UIPanel>();
			if ((bool)component)
			{
				component.alpha = 0f;
				HOTween.Init();
				HOTween.Kill(component);
				HOTween.To(component, 1f, new TweenParms().Prop("alpha", 1));
			}
		}
		if ((bool)humanoid.mobNavigationController && humanoid.gameObject.activeSelf)
		{
			humanoid.mobNavigationController.DisableNavigation();
			humanoid.mecanimWrapper.Idle(true);
		}
	}

	public void EnableControls(GameObject disablePanel)
	{
		disableControls = false;
		if ((bool)playerBehavior && playerBehavior.isMine)
		{
			if (base.gameObject.activeSelf)
			{
				StartCoroutine(HidePanelSmooth(disablePanel));
			}
			else
			{
				disablePanel.SetActive(false);
			}
		}
		if (effectWatcher.CanActivateControls())
		{
			humanoid.canMove = true;
			humanoid.canShoot = true;
			if ((bool)humanoid.mobNavigationController && humanoid.gameObject.activeSelf && !humanoid.isDead)
			{
				humanoid.mobNavigationController.StartMoving(humanoid.mobNavigationController.cSpeed);
				humanoid.mecanimWrapper.Idle(false);
			}
		}
	}

	private IEnumerator HidePanelSmooth(GameObject disablePanel)
	{
		UIPanel messagePanel = disablePanel.GetComponent<UIPanel>();
		if ((bool)messagePanel)
		{
			messagePanel.alpha = 1f;
			HOTween.Init();
			HOTween.Kill(messagePanel);
			HOTween.To(messagePanel, 0.5f, new TweenParms().Prop("alpha", 0));
		}
		yield return new WaitForSeconds(0.5f);
		disablePanel.SetActive(false);
	}
}
